// pages/transportPlanDetail/transportPlanDetail.ts
var url = require("../../utils/urls");
var commons = require("../../utils/common");
var tip = require("../../utils/tip");
var modelData = require("../../utils/data");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    item: {},
    current: 1,
    size: 10,
    totalPage: 0
  },

  getPlanDispatch: async function () {
    let requestUrl = url.getPlanDispatch
    let json = {
    }
    let data = await commons.postJson(requestUrl + "?current=" + this.data.current + "&size="
      + this.data.size + "&planNumber=" + this.data.item.planNumber, json);
    if (data.code == 200) {
      let resData = data.data
      resData.records.forEach((item, index) => {
        item.waybillStatusFont = commons.getFont(modelData.ysStatus, item.waybillStatus)
        resData.records.splice(index, 1, item)
      });
      this.setData({
        list: this.data.list.concat(resData.records),
        totalPage: Math.ceil(resData.total / this.data.size)
      })
    } else {
      tip.showToast(data.msg, 'error', 1000)
    }
  },

  loadMore(e) {
    console.log('加载更多')
    if (this.data.totalPage === 1) {
      return
    }

    if (this.data.current < this.data.totalPage) {
      this.setData({
        current: this.data.current + 1,
      })
      this.getPlanDispatch()
    }
  },

  goWaybillDetail(e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: "../waybillDetail/waybillDetail?waybillNumber=" + item.waybillNumber
    })
  },

  goWaybillBookingDetail(e) {
    let waybillNumber = e.currentTarget.dataset.waybillnumber
    wx.navigateTo({
      url: "../waybillBookingDetail/waybillBookingDetail?waybillNumber=" + waybillNumber,
    })
  },
  //拨打电话
  call(e) {
    let phone = e.currentTarget.dataset.phone
    commons.callPhone(phone)
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {
    if (e.item) {
      this.setData({
        item: JSON.parse(e.item)
      })
      this.getPlanDispatch()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})